#include <iostream>
#include <string>
#include <map>

using namespace std;

bool pr(int n)
{
    if (n <= 1)
    {
        return false;
    }
    for (int i=2; i < n; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    string str;
    getline(cin, str);
    
    str.erase(str.find_last_not_of(" \t\r\n") + 1); //удаление пробелов в конце строки
    map<string, int> M = {
    {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
    {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
  };


    int i = 0;
    size_t pos = 0;
    string words[3];
    while (i<3 && pos < str.length())
    {
        size_t nextpos = str.find(' ', pos);
        if (nextpos == string::npos)
        {
            nextpos = str.length();
        }
        words[i++] = str.substr(pos, nextpos - pos);
        pos = nextpos + 1;
    }
    
    if (i != 3)
    {
        cout<<"Wrong input"<<endl;
        return 1;
    }
    for (int j = 0; j < 3; j++)
    {
        if (M.find(words[j]) == M.end())
        {
            cout<<"Wrong input"<<endl;
            return 1;
        }
    }
    int n = M[words[0]]*100 + M[words[1]]*10 + M[words[2]];
    if (n < 100 || n > 999 || n <= 0)
    {
        cout<<"Wrong input"<<endl;
        return 0;
    }
    
    int closestpr = 0, lower = n, higher = n;
    bool found = false;
    while (!found)
    {
        if (pr(higher))
        {
            found = true;
            closestpr = higher;
        }
        else
        {
            higher ++;
        }
        if (pr(lower))
        {
            found = true;
            closestpr = lower;
        }
        else
        {
            lower--;
        }
    }
    
    cout<<closestpr<<endl;
    return 0;
}
